clear all
set more off, perm
set mem 10000000
set matsize 10000
version 13

*************************************************************************** 
*** Table and figures for JPE revisions: reduced-form economic outcomes ***
*************************************************************************** 

** Set file paths
do "$path_code/paths.do"

** Set graph scheme
cd "$path/code/analyze"
set scheme fb, perm

********************************************************************************
********************************************************************************

** Table 4: Reduced-form RD results for economic outcomes
{

use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)


***

use "$results/RDROBUST_outcomes_rf_secc.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
***	

use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

			
***	

use "$results/RDROBUST_outcomes_rf_ec.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

			
***	

use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
	
	
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes}" _n
file write tablewrite "\label{tab:rd_outcomes}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.87cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Each row reports results from a separate RD regression. " _n
file write tablewrite "In Panels B--C, we control for the 2001 level of the outcome variable. " _n
file write tablewrite "In Panels D--E, we control for the 2005 (or 2005--06) level of the outcome variable. " _n
file write tablewrite "RD robust regressions are otherwise identical to those in Table \ref{tab:rd_vdelec}. " _n
file write tablewrite "Optimal bandwidths range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Results are broadly robust to alternative controls, kernels, bandwidth algorithms, and standard errors.  " _n
file write tablewrite "The right column reports means of the outcome variable for villages below the 300-person cutoff. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Figure 7: Reduced-form RD results for select economic outcomes
{
copy "${results}/RDROBUST plots rf outcomes preferred/secc11_rural_cons_pc_fs_inreg_10.pdf" ///
		"${texfig}/secc11_rural_cons_pc_fs_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots rf outcomes preferred/ln_secc11_rural_cons_pc_fs_inreg_10.pdf" ///
		"${texfig}/ln_secc11_rural_cons_pc_fs_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots rf outcomes preferred/hh_ratio_fs_inreg_10.pdf" ///
		"${texfig}/hh_ratio_fs_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots rf outcomes preferred/tot_p11_fs_inreg_10.pdf" ///
		"${texfig}/tot_p11_fs_inreg_10.pdf" , replace

   // MAKE FIGURE
use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1
sum bw_lo if yvar=="secc11_rural_cons_pc"   
assert r(N)==1
local bw1 = string(r(mean),"%9.0f")  
sum bw_lo if yvar=="ln_secc11_rural_cons_pc"   
assert r(N)==1
local bw2 = string(r(mean),"%9.0f")  
 
   
file open tablewrite using "$texfig/figure_rd_outcomes_main.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Village-level RDs in expenditure, poverty, and population}" _n
file write tablewrite "\label{fig:rd_outcomes_main}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/secc11_rural_cons_pc_fs_inreg_10.pdf}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/ln_secc11_rural_cons_pc_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/hh_ratio_fs_inreg_10.pdf}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/tot_p11_fs_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD plots correspond to four regressions " _n
file write tablewrite "in Table \ref{tab:rd_outcomes}: rows 1--3 of Panel A, and row 1 of Panel B. " _n
file write tablewrite "See table notes for details." _n
file write tablewrite "Appendix Figures \ref*{fig:rd_secc}--\ref*{fig:rd_schools} display RD plots " _n 
file write tablewrite "for the other regressions in Table \ref{tab:rd_outcomes}." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Figure 8: Reduced-form expenditure coefficients for high-intensity splits (RD SHRUG and DD NSS)
{
use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1
keep if inlist(yvar,"secc11_rural_cons_pc","ln_secc11_rural_cons_pc")
assert _N==2
gsort -yvar
local yvar1 = yvar[1]
local split1 = "pooled"
local beta1 = beta_robust[1] / ymean[1]
local lci1 = lci_robust[1] / ymean[1]
local uci1 = uci_robust[1] / ymean[1]
local yvar2 = yvar[2]
local split2 = "pooled"
local beta2 = exp(beta_robust[2])-1
local lci2 = exp(lci_robust[2])-1
local uci2 = exp(uci_robust[2])-1
 
use "$results/RDROBUST_outcomes_rf_shrug_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1
keep if inlist(yvar,"secc11_rural_cons_pc","ln_secc11_rural_cons_pc")
assert _N==2
local yvar3 = yvar[1]
local split3 = "hi intens"
local beta3 = beta_robust[1] / ymean[1]
local lci3 = lci_robust[1] / ymean[1]
local uci3 = uci_robust[1] / ymean[1]
local yvar4 = yvar[2]
local split4 = "hi intens"
local beta4 = exp(beta_robust[2])-1
local lci4 = exp(lci_robust[2])-1
local uci4 = exp(uci_robust[2])-1

use "$results/nss_reg_results.dta", clear
keep if panel=="district-year collapsed"
keep if regs=="ols"
keep if inlist(yvar,"mth_pc_expE1","log_exp_30E1")
keep if inlist(ytag,"_dec30")
keep if ifs==""
keep if inlist(fes,"year c.year#exp05_st_4ile c.year#exp05_ntl_10ile stdt")
assert _N==2
gsort -yvar
local yvar5 = yvar[1] + ytag[1]
local split5 = "pooled"
local beta5 = beta[1] / ymean_pooled[1]
local lci5 = ci95_lo[1] / ymean_pooled[1]
local uci5 = ci95_hi[1] / ymean_pooled[1]
local yvar6 = yvar[2] + ytag[2]
local split6 = "pooled"
local beta6 = exp(beta[2])-1
local lci6 = exp(ci95_lo[2])-1
local uci6 = exp(ci95_hi[2])-1

use "$results/nss_reg_results.dta", clear
keep if panel=="district-year collapsed"
keep if regs=="ols (DPR interaction)"
keep if inlist(yvar,"mth_pc_expE1","log_exp_30E1")
keep if inlist(ytag,"_dec30")
keep if ifs==""
keep if inlist(fes,"year c.year#exp05_st_4ile c.year#exp05_ntl_10ile stdt")
assert _N==2
gsort -yvar
local yvar7 = yvar[1] + ytag[1]
local split7 = "hi intens"
local beta7 = beta_dpr_hi[1] / ymean_dpr_hi[1]
local lci7 = ci95_lo_dpr_hi[1] / ymean_dpr_hi[1]
local uci7 = ci95_hi_dpr_hi[1] / ymean_dpr_hi[1]
local yvar8 = yvar[2] + ytag[2]
local split8 = "hi intens"
local beta8 = exp(beta_dpr_hi[2])-1
local lci8 = exp(ci95_lo_dpr_hi[2])-1
local uci8 = exp(ci95_hi_dpr_hi[2])-1

clear
set obs 8
gen yvar = ""
gen split = ""
gen beta = .
gen lci = .
gen uci = .
forvalues i = 1/8 {
    foreach v of varlist * {
	    cap replace `v' = ``v'`i'' in `i'
		cap replace `v' = "``v'`i''" in `i'
	}
}
gen x = ceil(_n/2)
gen log = substr(yvar,1,2)=="ln" | substr(yvar,1,3)=="log"
replace x = x - 0.1 if log==0
replace x = x + 0.1 if log==1


twoway ///
	(rspike uci lci x , lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta x if log==0, msize(medsmall) mc(gs4) msymbol(O)) ///
	(scatter beta x if log==1, msize(medsmall) mc(gs9) msymbol(T)) ///	
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("% change in expenditure", size(small)) xtitle("", size(small)) ///
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(-.03 "-3" 0 "0" .03 "3" .06 "6" .09 "9" .12 "12" .15 "15",nogrid angle(0) labsize(small)) ///
	xlabel(1 `" "RD SHRUG" "all districts" "' ///
	       2 `" "RD SHRUG" "high intensity" "' ///
	       3 `" "NSS DD Q25" "all districts" "' ///
		   4  `" "NSS DD Q25" "high intensity" "', labsize(small)) ///
	xscale(range(0.7 4.3)) ///
 	legend(order(2 "Levels" 3 "Logs") size(small) bplace(10) ring(0)) 	///
	aspect(0.36)
cap erase "$texfig/figure_rf_expenditure_hi_intens-eps-converted-to.pdf" 
graph export "$texfig/figure_rf_expenditure_hi_intens.eps", replace 


   // MAKE FIGURE
cap file close tablewrite
file open tablewrite using "$texfig/figure_rf_expenditure_hi_intens.tex", write text replace

file write tablewrite "\begin{figure}[t]\centering " _n
file write tablewrite "\caption{Reduced-form expenditure effects, all districts vs.\ high-intensity districts}" _n
file write tablewrite "\label{fig:rf_expenditure_hi_intens}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\includegraphics[width=0.8\textwidth, trim={0 22mm 0 22mm}, clip]{${texfig_short}/figure_rf_expenditure_hi_intens.eps} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This figure plots reduced-form estimates for expenditure per capita. " _n
file write tablewrite "For regressions where the outcome variable is in levels (circles), we divide point " _n
file write tablewrite "estimates by within-sample means of the outcome variable to interpret as percent changes. " _n
file write tablewrite "For regressions where the outcome variable is in logs (triangles), we convert point estimates " _n
file write tablewrite "to percent changes (i.e., \$\exp(\beta)-1\$). " _n
file write tablewrite "\`\`All districts'' estimates pool all 130 RGGVY 10th-Plan districts. " _n
file write tablewrite "\`\`High intensity'' estimates use only the 90 RGGVY 10th-Plan districts " _n
file write tablewrite "where at least 60\% of villages received treatment. " _n
file write tablewrite "Whiskers display 95\% confidence intervals. " _n
file write tablewrite "We report the corresponding point estimates in (from left to right): " _n
file write tablewrite "Table \ref{tab:rd_outcomes}; and Appendix Tables \ref*{tab:rd_outcomes_hi_intens}, " _n
file write tablewrite "\ref*{tab:nss_reduced_form_quintiles}, and \ref*{tab:nss_rf_intens}. " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Figure 9: Reduced-form DD population splits, economic census outcomes
{
use "${results}/dd_results_outcomes_ec_4years.dta", clear
keep if dd_model=="pop bins"
keep if ifs==""
keep if fes=="pca01_id year#popbin exp05_st_4ile#year exp05_ntl_10ile#year st_code#c.year c.(lit_p_01 work_p_01 work_f_01 vd_geo_a_01 vd_geo_k_town_01 vd_edu_d_01 vd_hea_d_medi_01 vd_wat_d_any_01 vd_tra_d_bus_01 vdpr_tra_d_app_pr_01 vd_pwr_d_all_01 vd_pwr_d_any_01 vdpr_pwr_d_oth_01 vd_pwr_d_agr_01 vd_pwr_d_dom_01 vd_fin_d_ac_soc_01)#year"
dropmiss, force
assert _N==2
local nobs = string(nobs[1],"%9.0fc")

drop ymean
reshape long beta se tscore pvalue ci95_lo ci95_hi ymean ymean13, i(yvar) j(pop) string
replace pop = subinstr(pop,"_"," ",2)
replace pop = word(pop,1)
destring pop, replace
replace pop = pop + 250

sort yvar pop
sum beta if yvar=="ec_firms" & pop==3250
local betaF = r(mean)
sum ymean if yvar=="ec_firms" & pop==3250
local ymeanF = r(mean)
sum beta if yvar=="ec_employees" & pop==3250
local betaE = r(mean)
sum ymean if yvar=="ec_employees" & pop==3250
local ymeanE = r(mean)
global magF = `betaF'/`ymeanF'
global magE = `betaE'/`ymeanE'
di $magF
di $magE
local ymeanF = string(`ymeanF',"%9.0f")
local ymeanE = string(`ymeanE',"%9.0f")
local magF = string(100*`betaF'/`ymeanF',"%9.0f")
local magE = string(100*`betaE'/`ymeanE',"%9.0f")

twoway ///
	(rspike ci95_hi ci95_lo pop if yvar=="ec_firms", lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta pop if yvar=="ec_firms", msize(medsmall) mc(gs4) msymbol(O)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("Binned DD coefficient (95% CI)", size(medium)) xtitle("Village population bin", size(medium)) ///
	title("Number of firms in village", color(black) size(large)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(-20(10)30,nogrid angle(0) labsize(medium)) ///
	xlabel(0 500 1000 1500 2000 2500 3000 "3000+", labsize(medium)) ///
 	legend(off) 	
cap erase "$texfig/figure_dd_ec_firms_by_popbin-eps-converted-to.pdf"
graph export "$texfig/figure_dd_ec_firms_by_popbin.eps", replace 

twoway ///
	(rspike ci95_hi ci95_lo pop if yvar=="ec_employees", lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta pop if yvar=="ec_employees", msize(medsmall) mc(gs4) msymbol(O)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("Binned DD coefficient (95% CI)", size(medium)) xtitle("Village population bin", size(medium)) ///
	title("Number of employees in village", color(black) size(large)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(-60(30)60,nogrid angle(0) labsize(medium)) ///
	xlabel(0 500 1000 1500 2000 2500 3000 "3000+", labsize(medium)) ///
 	legend(off)
cap erase "$texfig/figure_dd_ec_employees_by_popbin-eps-converted-to.pdf"
graph export "$texfig/figure_dd_ec_employees_by_popbin.eps", replace 


	 
   // MAKE FIGURE
cap file close tablewrite
file open tablewrite using "$texfig/figure_dd_ec_by_popbin.tex", write text replace

file write tablewrite "\begin{figure}[p]\centering " _n
file write tablewrite "\caption{Village-level DD of Economic Census outcomes, by village population bin}" _n
file write tablewrite "\label{fig:dd_ec_by_popbin}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth, trim={0 0mm 0 0mm}, clip]{${texfig_short}/figure_dd_ec_firms_by_popbin.eps}~ " _n
file write tablewrite "\includegraphics[width=0.495\textwidth, trim={0 0mm 0 0mm}, clip]{${texfig_short}/figure_dd_ec_employees_by_popbin.eps} \\ " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This figure plots DD coefficients by village population bin, " _n
file write tablewrite "for outcomes in Panel D of Table \ref{tab:rd_outcomes}. Regressions use a panel of four Economic Census waves " _n
file write tablewrite "(1990, 1998, 2005, 2013) with `nobs' village-year observations. We interact DD treatment " _n
file write tablewrite "(\$\mathbf{1}\big[\text{10th-Plan district}\big] \times \mathbf{1}\big[2013\big]\$) with bins of " _n
file write tablewrite "2001 village population (\$\le\$500, 501--1000, \dots, 2501--3000, \$>\$3000). " _n
file write tablewrite "In the \$>\$3000 bin, the average village had `ymeanF' firms and `ymeanE' employees---meaning  " _n
file write tablewrite "that our DD estimates for this bin represent `magF'\% and `magE'\% increases, respectively. " _n
file write tablewrite "We interact year fixed effects with population bins, and with two sets of quantiles in 2005 " _n
file write tablewrite "expenditure per capita at the district level (within-state quartiles and national deciles). " _n
file write tablewrite "Regressions also include village fixed effects, state-specific linear trends, and " _n
file write tablewrite "year-specific slopes in 2001 village-level covariates  (which increase precision). " _n
file write tablewrite "Whiskers display 95\% confidence intervals, with standard errors clustered by district. " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Table A5: District-level DD for HPCA electric lighting and TV variables
{
use "${results}/dd_outcomes_census_distlevel.dta", clear
keep if inlist(yvar,"hpca_msl_elec","hpca_assets_tv")
keep if fes=="year stdt exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
assert _N==2

gen c = .
replace c = 1 if yvar=="hpca_msl_elec" 
replace c = 2 if yvar=="hpca_assets_tv" 
assert c!=.	
sort c

forvalues c = 1/2 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if  pvalue[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs[`c'],"%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	


   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_dd_dist_msl_elec.tex", write text replace

file write tablewrite "\begin{table}[h!]\centering " _n
file write tablewrite "\caption{District-level DD of household appliance ownership, Census variables}" _n
file write tablewrite "\label{tab:dd_dist_msl_elec}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc}" _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{2}{c}{Outcome: Share of rural households with} \\ " _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite " \cline{2-3} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite " \\" _n
file write tablewrite " & ~~Electric lighting~~ & TV  \\ " _n
file write tablewrite "& (1) & (2) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\$\mathbf{1}\big[\text{10th-Plan district}\big] \times \mathbf{1}\big[2011\big]\$ ~~~& " _n
file write tablewrite "\$`beta1'$`stars1' & $`beta2'$`stars2' \\" _n
file write tablewrite "& ~~~~$(`se1')$~~~~ & ~~~~$(`se2')$~~~~ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "Mean of dep var & `ymean1' & `ymean2' \\" _n
file write tablewrite "District-year observations &`nobs1' & `nobs2' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This table replicates Columns (4) and (6) of Table  " _n
file write tablewrite "\ref*{tab:nss_first_stage} using analogous variables from the 2001 and 2011 Census. " _n
file write tablewrite "We collapse 2011 village-level outcomes to the district level, weighting by " _n
file write tablewrite "the number of rural households (which aligns with NSS sampling weights).  " _n
file write tablewrite "2001 electric lighting and TV ownership rates are only available at the Census block level, " _n
file write tablewrite "and we use the same method to collapse them to the district level. " _n
file write tablewrite "Estimation samples include villages in 10th-Plan districts, 11th-Plan districts, " _n
file write tablewrite "and non-RGGVY districts, without restricting village size. " _n
file write tablewrite "All regressions include: district fixed effects; year fixed effects; state-specific linear trends;  " _n
file write tablewrite "linear trends in state quartiles of 2005 household expenditures per capita; " _n 
file write tablewrite "and linear trends in national deciles of 2005 household expenditures per capita. " _n
file write tablewrite "Standard errors are clustered at the district level." _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite
}

********************************************************************************
********************************************************************************

** Table A13: RD results for main source of lightihg = electric
{

use "$results/RDROBUST_outcomes_rf_census.dta", clear
append using "$results/RDROBUST_outcomes_rf_census_dpr.dta"
keep if regexm(yvar,"elec") | regexm(yvar,"bad")
keep if rf_step==1
keep if inlist(dprtag,"","hi_vill")
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="hpca11_msl_elec" & dprtag==""
replace c = 2 if yvar=="hpca11_msl_elec" & dprtag=="hi_vill"
replace c = 3 if yvar=="hpca11_msl_bad" & dprtag==""
replace c = 4 if yvar=="hpca11_msl_bad" & dprtag=="hi_vill"

keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
sort c

forvalues c = 1/4 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	local ndist`c' = string(ndist[`c'],"%9.0fc")
}	
		
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_msl_elec.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- households' main source of lighting}" _n
file write tablewrite "\label{tab:rd_msl_elec}" _n
file write tablewrite "\vspace{-3mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{5}{c}{Share of HHs whose main source of lighting is \dots} \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-6} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite "\\" _n
file write tablewrite "& \multicolumn{2}{c}{Electricity} &&  \multicolumn{2}{c}{Kerosene} \\" _n
file write tablewrite "& ~~~~~(1)~~~~~ & ~~~~~(2)~~~~~ && ~~~~~(3)~~~~~ & ~~~~~(4)~~~~~ \\ " _n
file write tablewrite "\cline{2-3} \cline{5-6} \\" _n
file write tablewrite "\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big]$ & " _n
file write tablewrite "$`beta1'$`stars1' & $`beta2'$`stars2' && $`beta3'$`stars3' & $`beta4'$`stars4' \\" _n
file write tablewrite "& $(`se1')$ & $(`se2')$ && $(`se3')$ & $(`se4')$ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "High-intensity districts only & & Yes && & Yes \\ " _n 
file write tablewrite "[0.5em] " _n
file write tablewrite "Mean of dep var (\$<300\$)~ & `ymean1' & `ymean2' && `ymean3' & `ymean4'  \\ " _n
file write tablewrite "Optimal bandwidth & `bw1' & `bw2' && `bw3' & `bw4' \\ " _n
file write tablewrite "Village observations &`nobs1' & `nobs2' && `nobs3' & `nobs4' \\ " _n
file write tablewrite "Number of 10th-Plan districts~~ & `ndist1' & `ndist2' && `ndist3' & `ndist4' \\ " _n 
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Regressions are identical to those in Table \ref*{tab:rd_vdelec}, " _n
file write tablewrite "except Columns (2) and (4) restrict the sample to the subset of RGGVY 10th-Plan districts where the program " _n
file write tablewrite "treated at least 60\% of all villages in the district (per RGGVY district-level " _n
file write tablewrite "implementation data).  " _n
file write tablewrite "This reduces the main RD sample from 129 districts in 12 states to 89 districts in 11 states. " _n
file write tablewrite "Columns (1) and (3) use the main RD sample. The outcome variables are the share of households " _n
file write tablewrite "in the village using electricity (or kerosene) as primary lighting source. " _n
file write tablewrite "See notes under Table \ref*{tab:rd_vdelec} for further details. " _n
file write tablewrite "Results are robust to alternative kernels and bandwidth algorithms. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A15: Reduced-form RD results for economic outcomes, RGGVY-intensive districts
{
use "$results/RDROBUST_outcomes_rf_shrug_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools_dpr.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if dprtag=="hi_vill"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	

			
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_hi_intens.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, high-intensity districts}" _n
file write tablewrite "\label{tab:rd_outcomes_hi_intens}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes},  " _n
file write tablewrite "except that here we restrict our RD sample to the subset of RGGVY 10th-Plan districts " _n
file write tablewrite "where the program treated at least 60\% of all villages in the district (per RGGVY " _n
file write tablewrite "district-level implementation data). "
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "See notes under Tables \ref*{tab:rd_outcomes} and \ref{tab:rd_vdelec_hi_intens} for further details. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A19: Reduced-form RD results for economic outcomes, districts with >=10 hours/day of power
{

use "$results/RDROBUST_outcomes_rf_shrug_hrs.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if hrstag=="over10hrs"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc_hrs.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if hrstag=="over10hrs"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census_hrs.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if hrstag=="over10hrs"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec_hrs.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if hrstag=="over10hrs"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools_hrs.dta", clear
keep if kernel=="Triangular"
keep if bwmethod=="mserd"
keep if fe=="STFEfs*"
keep if hrstag=="over10hrs"
assert regexm(ifs,"in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20")
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	

			
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_hours.tex", write text replace
 
file write tablewrite "\begin{table}[h]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, districts with \$\ge10\$ hours/day of power}" _n
file write tablewrite "\label{tab:rd_outcomes_hours}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes},  " _n
file write tablewrite "except that here we restrict our RD sample to the subset of districts where electrified villages " _n
file write tablewrite "received at least 10 hours per day of all-sector power supply in 2011. " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "The results for grades 6--8 enrollment and passing are not robust to alternative kernels and bandwidth algorithms. " _n
file write tablewrite "See notes under Tables \ref*{tab:rd_outcomes} and \ref{tab:diff_in_disc_vdelec_hours} for further details. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A22: Reduced-form RD results for additional economic outcomes
{

use "$results/RDROBUST_outcomes_rf_secc.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="index_secc11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==1
set obs 1
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 1/1 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)

		
***	

use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 2 if yvar=="work_pooled_hh_m_11" 
replace c = 3 if yvar=="work_pooled_hh_f_11"
replace c = 4 if yvar=="work_main_p_11"
replace c = 5 if yvar=="work_marg_p_11"
replace c = 6 if yvar=="hpca11_assets_tel_l_m_b" 
replace c = 7 if yvar=="hpca11_assets_tv"
replace c = 8 if yvar=="hpca11_assets_bic" 
replace c = 9 if yvar=="hpca11_assets_smm"
replace c = 10 if yvar=="hpca11_assets_rt"
replace c = 11 if yvar=="hpca11_assets_cl_no_int"
replace c = 12 if yvar=="hpca11_assets_cl_int"
replace c = 13 if yvar=="hpca11_assets_none" 
replace c = 14 if yvar=="hpca11_cook_good" 
replace c = 15 if yvar=="hpca11_msl_bad"
replace c = 16 if yvar=="hpca11_mat_f_m" 
replace c = 17 if yvar=="hpca11_mat_r_gtbw"
replace c = 18 if yvar=="hpca11_t_hh_d"
replace c = 19 if yvar=="pct_sown_11" 
replace c = 20 if yvar=="pct_irr_11"
replace c = 21 if yvar=="vd_wat_d_tubewell_11"
replace c = 22 if yvar=="vd_fin_d_ac_soc_11" 
replace c = 23 if yvar=="vdp_com_d_phone_mob_11"
replace c = 24 if yvar=="index_hpca11"
replace c = 25 if yvar=="index_vd11"
replace c = 26 if yvar=="work_p_11" 

keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==25
set obs 26
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 2/26 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

	
***	

use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 27 if yvar=="tot_enroll_all2014" 
replace c = 28 if yvar=="tot_enroll_boys2014"
replace c = 29 if yvar=="tot_enroll_girls2014" 
replace c = 30 if yvar=="g15_enroll_all2011"
replace c = 31 if yvar=="g68_enroll_all2011"
replace c = 32 if yvar=="tot_enroll_all2011"
replace c = 33 if yvar=="tot_enroll_boys2011"
replace c = 34 if yvar=="tot_enroll_girls2011"
replace c = 35 if yvar=="tot_enroll_allPOST"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 35
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 27/35 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
	
	
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_bonus.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- additional reduced-form outcomes}" _n
file write tablewrite "\label{tab:rd_outcomes_bonus}" _n
file write tablewrite "\vspace{-3mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.98cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{F.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "~~Household workers, male           & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Household workers, female         & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Workers, \$\ge 6\$ months of year & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Workers, \$< 6\$ months of year   & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{G.} \underline{Household asset ownership (2011)}} \\ " _n
file write tablewrite "~~Share HH with telephone             & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "~~Share HH with TV                    & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share HH with bicycle               & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Share HH with motorcycle            & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "~~Share HH with radio                 & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Share HH with computer, no internet & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Share HH with computer internet     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Share HH with no assets             & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{H.} \underline{Housing characteristics (2011)}} \\ " _n
file write tablewrite "~~Share HH with elec/gas cooking    & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Share HH with kerosene lighting   & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "~~Share HH with mud floors          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Share HH with thatched roofs      & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "~~Share HH that are dilapidated     & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{I.} \underline{Community-wide outcomes (2011)}~~} \\ " _n
file write tablewrite "~~Share of village land planted     & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~Share of village land irrigated   & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~1/0 village has tubewell          & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "~~1/0 village has ag credit society & $`beta22'$`stars22' & $(`se22')$ & $[`lci22',`uci22']$ & `ymean22' \\" _n
file write tablewrite "~~1/0 village has cell service      & $`beta23'$`stars23' & $(`se23')$ & $[`lci23',`uci23']$ & `ymean23' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{J.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "~~\# students enrolled, grades 1--8  & $`beta27'$`stars27' & $(`se27')$ & $[`lci27',`uci27']$ & `ymean27' \\" _n
file write tablewrite "~~\# boys enrolled, grades 1--8      & $`beta28'$`stars28' & $(`se28')$ & $[`lci28',`uci28']$ & `ymean28' \\" _n
file write tablewrite "~~\# girls enrolled, grades 1--8     & $`beta29'$`stars29' & $(`se29')$ & $[`lci29',`uci29']$ & `ymean29' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{K.} \underline{School outcomes (2011--12 school year)}~~} \\ " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta30'$`stars30' & $(`se30')$ & $[`lci30',`uci30']$ & `ymean30' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta31'$`stars31' & $(`se31')$ & $[`lci31',`uci31']$ & `ymean31' \\" _n
file write tablewrite "~~\# students enrolled, grades 1--8  & $`beta32'$`stars32' & $(`se32')$ & $[`lci32',`uci32']$ & `ymean32' \\" _n
file write tablewrite "~~\# boys enrolled, grades 1--8      & $`beta33'$`stars33' & $(`se33')$ & $[`lci33',`uci33']$ & `ymean33' \\" _n
file write tablewrite "~~\# girls enrolled, grades 1--8     & $`beta34'$`stars34' & $(`se34')$ & $[`lci34',`uci34']$ & `ymean34' \\" _n
file write tablewrite "[0.45em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{L.} \underline{Indexed and aggregated outcomes (2011)}~~} \\ " _n
file write tablewrite "~~Index of 5 income/wealth variables       & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & $`ymean1'$ \\" _n
file write tablewrite "~~Index of 16 household characteristics    & $`beta24'$`stars24' & $(`se24')$ & $[`lci24',`uci24']$ & $`ymean24'$ \\" _n
file write tablewrite "~~Index of 27 community outcomes           & $`beta25'$`stars25' & $(`se25')$ & $[`lci25',`uci25']$ & $`ymean25'$ \\" _n
file write tablewrite "~~Total workers as share of population     & $`beta26'$`stars26' & $(`se26')$ & $[`lci26',`uci26']$ & `ymean26' \\" _n
file write tablewrite "~~School enrollment, grades 1--8, 2011--15 avg.\  & $`beta35'$`stars35' & $(`se35')$ & $[`lci35',`uci35']$ & `ymean35' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-4mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Each row reports results from a separate RD regression, for outcomes not included in Table \ref*{tab:rd_outcomes}. " _n
file write tablewrite "In Panels G--I and Panel L (rows 2--4), we control for the 2001 level of the outcome variable (except for computers, where 2001 data are unavailable)." _n
file write tablewrite "In Panels J--K and Panel L (row 5), we control for the 2005--06 level of the outcome variable." _n
file write tablewrite "Panel L outcomes are pooled indexes and averages that reflect outcomes in: " _n
file write tablewrite "Panel A (income/wealth); Panels G--H (household); Panel I (community); " _n
file write tablewrite "Panels C and F (workers); and Panels E and J--K (schooling)." _n 
file write tablewrite "RD robust models are otherwise identical to those in Table \ref*{tab:rd_vdelec}. " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Results are broadly robust to alternative controls, kernels, bandwidth algorithms, and standard errors." _n
file write tablewrite "Estimates for telephones and mud floors are not robust to alternative weighting kernels and bandwidth algorithms. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A23: Reduced-form DD results for economic outcomes (village and district levels)
{

use "$results/dd_outcomes_census_pooled.dta", clear
keep if fes=="year pca01_id exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
keep if vce=="cluster stdt"
keep if beta!=.

gen c = .
replace c = 1 if yvar=="pct_06"
replace c = 2 if yvar=="work_pooled_ag_p"
replace c = 3 if yvar=="work_pooled_ag_m" 
replace c = 4 if yvar=="work_pooled_ag_f"
replace c = 5 if yvar=="work_pooled_ot_p"
replace c = 6 if yvar=="work_pooled_ot_m" 
replace c = 7 if yvar=="work_pooled_ot_f"
replace c = 8 if yvar=="index_vd"
replace c = 9 if yvar=="work_p" 
sort c
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 9
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 1/9 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pvalue[`c'] <= 0.05  {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10  {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(ci95_lo[`c'], "%9.3f")
	local uci`c' = string(ci95_hi[`c'], "%9.3f")
	
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	
			
***	

use "$results/dd_results_outcomes_ec_4years.dta", clear
keep if fes=="pca01_id year exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
keep if ifs==""
keep if beta!=.
assert _N==2

gen c = .
replace c = 10 if yvar=="ec_firms" 
replace c = 11 if yvar=="ec_employees"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 11
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 10/11 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pvalue[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10  {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(ci95_lo[`c'], "%9.3f")
	local uci`c' = string(ci95_hi[`c'], "%9.3f")

	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

***	

use "$results/dd_results_outcomes_dise_allyears.dta", clear
keep if fes=="pca01_id year exp05_st_4ile#c.year exp05_ntl_10ile#c.year c.year#st_code"
keep if ifs==""
keep if beta!=.
keep if inlist(yvar,"g15_enroll_all","g68_enroll_all","tot_pass60_prev45","tot_pass60_prev78","tot_enroll_all")
keep if dd_var==2
assert _N==5

gen c = .
replace c = 12 if yvar=="g15_enroll_all" 
replace c = 13 if yvar=="g68_enroll_all"
replace c = 14 if yvar=="tot_pass60_prev45" 
replace c = 15 if yvar=="tot_pass60_prev78"
replace c = 16 if yvar=="tot_enroll_all"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==5
set obs 16
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 12/16 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pvalue[`c'] <= 0.05  {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10  {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(ci95_lo[`c'], "%9.3f")
	local uci`c' = string(ci95_hi[`c'], "%9.3f")
	
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

***	


   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_dd_outcomes.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level and district-level DD -- reduced-form outcomes}" _n
file write tablewrite "\label{tab:dd_outcomes}" _n
file write tablewrite "\vspace{-3mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& DD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.87cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2001 \& 2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Share population age 0--6          & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Average household size \$\dagger\$ & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2001 \& 2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (1990, 1998, 2005, 2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Number of firm employees & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2005--15)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{L.} \underline{Indexed and aggregated outcomes (2001 \& 2011)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Index of 19 community outcomes           & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & $`ymean8'$ \\" _n
file write tablewrite "~~Total workers as share of population    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "~~School enrollment, grades 1--8, 2005--15~~~        & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Each row reports results from a separate DD regression pooling villages of all sizes,  " _n
file write tablewrite "with panel years indicated in subheaders (as dictated by each respective data source). " _n
file write tablewrite "A dagger (\$\dagger\$) indicates collapsed district-level DD regressions (as in Table \ref{tab:dd_dist_vdelec}), " _n
file write tablewrite "for variables that are unavailable at the village level in the 2001 Census. " _n 
file write tablewrite "All other regressions use village-level data and village fixed effects (as in Table \ref{tab:dd_vdelec}). " _n
file write tablewrite "For yearly school outcomes, we estimate a staggered rollout of 10th-Plan funds (as in Column (2) of Table \ref{tab:dd_village_lights}). " _n
file write tablewrite "We lack pre-RGGVY observations for outcomes in Panel A of Table \ref*{tab:rd_outcomes}, which precludes applying our DD strategy." _n
file write tablewrite "All regressions include year fixed effects, both sets of 2005 expenditure trends, and state-specific trends. " _n
file write tablewrite "Standard errors are clustered by district. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Figures A10, A11, A12: Reduced-form RD plots, for outcomes not included in main text
{
local plotsA = "pct_hh_mnth_inc_5_10 pct_hh_salaried_job secc11_inc_cultiv_share"
local plotsB = "pct_06_11 hpca11_h_size_avg"
local plotsC = "work_pooled_ag_p_11 work_pooled_ag_m_11 work_pooled_ag_f_11 work_pooled_ot_p_11 work_pooled_ot_m_11 work_pooled_ot_f_11"
local plotsD = "ec_firms2013 ec_employees2013"
local plotsE = "g15_enroll_all2014 g68_enroll_all2014 tot_pass60_prev452014 tot_pass60_prev782014"

foreach f in `plotsA' `plotsB' `plotsC' `plotsD' `plotsE' {
	copy "${results}/RDROBUST plots rf outcomes preferred/`f'_fs_inreg_10.pdf" "${texfig}/`f'_fs_inreg_10.pdf" , replace
}

   // MAKE FIGURE, Panels A--B
use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1
sum bw_lo if yvar=="hpca11_h_size_avg"   
assert r(N)==1
local bw1 = string(r(mean),"%9.0f")  
   
file open tablewrite using "$texfig/figure_rd_secc.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Village-level RDs in income and demographic indicators}" _n
file write tablewrite "\label{fig:rd_secc}" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/secc11_inc_cultiv_share_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/pct_hh_mnth_inc_5_10_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/pct_hh_salaried_job_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/pct_06_11_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/hpca11_h_size_avg_fs_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- These RD plots correspond to the regressions in Panels A--B of Table \ref*{tab:rd_outcomes}. " _n
file write tablewrite "See table notes for details." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite


   // MAKE FIGURE, Panels C--D
file open tablewrite using "$texfig/figure_rd_labor.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Village-level RDs in labor and firm outcomes}" _n
file write tablewrite "\label{fig:rd_labor}" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ag_p_11_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ot_p_11_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ag_m_11_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ot_m_11_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ag_f_11_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_pooled_ot_f_11_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/ec_firms2013_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/ec_employees2013_fs_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- These RD plots correspond to the regressions in Panels C--D of Table \ref*{tab:rd_outcomes}. " _n
file write tablewrite "See table notes for details." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite


   // MAKE FIGURE, Panel E
use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1
sum bw_lo if yvar=="g15_enroll_all2014"   
assert r(N)==1
local bw1 = string(r(mean),"%9.0f") 

file open tablewrite using "$texfig/figure_rd_schools.tex", write text replace
 
file write tablewrite "\begin{figure}[h]\centering" _n
file write tablewrite "\caption{Village-level RDs in school outcomes}" _n
file write tablewrite "\label{fig:rd_schools}" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/g15_enroll_all2014_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/g68_enroll_all2014_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/tot_pass60_prev452014_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/tot_pass60_prev782014_fs_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- These RD plots correspond to the regressions in Panel E of Table \ref*{tab:rd_outcomes}. " _n
file write tablewrite "Pass rate data reported for the 2014--2015 school year reflect student outcomes from the previous academic year. " _n
file write tablewrite "See table notes for details." _n
file write tablewrite "The statistically imprecise discontinuity estimate for grade 1--5 enrollment " _n
file write tablewrite "changes signs when we increase the RD bandwidth to 200 " _n
file write tablewrite "(from the optimal bandwidth of `bw1' in row 1 of Panel E). " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table B1: Reduced-form RD results for economic outcomes, sensitivity table: Epanechnikov kernel
{

use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if kernel=="Epanechnikov"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc.dta", clear
keep if kernel=="Epanechnikov"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if kernel=="Epanechnikov"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec.dta", clear
keep if kernel=="Epanechnikov"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if kernel=="Epanechnikov"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	

			
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_sens_epa.tex", write text replace
 
file write tablewrite "\begin{table}[h]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, Epanechnikov kernel}" _n
file write tablewrite "\label{tab:rd_outcomes_sens_epa}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes},  " _n
file write tablewrite "except that here we apply RD robust with an Epanechnikov kernel instead of our preferred triangular kernel. " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table B2: Reduced-form RD results for economic outcomes, sensitivity table: uniform kernel
{
use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if kernel=="Uniform"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc.dta", clear
keep if kernel=="Uniform"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if kernel=="Uniform"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec.dta", clear
keep if kernel=="Uniform"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if kernel=="Uniform"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
		
		
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_sens_uni.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, uniform kernel}" _n
file write tablewrite "\label{tab:rd_outcomes_sens_uni}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes},  " _n
file write tablewrite "except that here we apply RD robust with a uniform kernel instead of our preferred triangular kernel. " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Table B3: Reduced-form RD results for economic outcomes, sensitivity table: CER bandwidth
{

use "$results/RDROBUST_outcomes_rf_shrug.dta", clear
keep if bwmethod=="cerrd"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc.dta", clear
keep if bwmethod=="cerrd"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census.dta", clear
keep if bwmethod=="cerrd"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec.dta", clear
keep if bwmethod=="cerrd"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools.dta", clear
keep if bwmethod=="cerrd"
keep if fe=="STFEfs*"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
		
		
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_sens_cer.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, CER bandwidth}" _n
file write tablewrite "\label{tab:rd_outcomes_sens_cer}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes},  " _n
file write tablewrite "except that here we apply RD robust using the CER-optimal bandwidth selection algorithm (\texttt{cerrd}) " _n
file write tablewrite "instead of our preferred MSE-optimal algorithm (\texttt{mserd}). " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite
	

}

********************************************************************************
********************************************************************************

** Table B4: Reduced-form RD results for economic outcomes, adding in states with bad/missing shapefiles
{

use "$results/RDROBUST_outcomes_rf_shrug_badshapefiles.dta", clear
keep if rf_step==1
assert ifs=="in_rf_sample==1 & pop_mismatch20==0"
assert fe=="STFErf*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="secc11_rural_cons_pc" 
replace c = 2 if yvar=="ln_secc11_rural_cons_pc"
replace c = 3 if yvar=="secc11_inc_cultiv_share" 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3

forvalues c = 1/3 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if `c'==1 {
		local beta`c' = string(beta_robust[`c'],"%9.3f")
		local se`c' = string(se_robust[`c'],"%9.3f")
	}	
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	if `c'==1 {
		local lci`c' = string(lci_robust[`c'], "%9.3f")
		local uci`c' = string(uci_robust[`c'], "%9.3f")
	}
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
	if `c'==1 {
		local ymean`c' = string(ymean[`c'],"%9.3f")
	}
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)



***

use "$results/RDROBUST_outcomes_rf_secc_badshapefiles.dta", clear
keep if rf_step==1
assert ifs=="in_rf_sample==1 & pop_mismatch20==0"
assert fe=="STFErf*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 4 if yvar=="hh_ratio" 
replace c = 5 if yvar=="pct_hh_mnth_inc_5_10"
replace c = 6 if yvar=="pct_hh_salaried_job"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==3
set obs 6
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 4/6 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
		
***	

use "$results/RDROBUST_outcomes_rf_census_badshapefiles.dta", clear
keep if rf_step==1
assert ifs=="in_rf_sample==1 & pop_mismatch20==0"
assert fe=="STFErf*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 7 if yvar=="tot_p11" 
replace c = 8 if yvar=="pct_06_11"
replace c = 9 if yvar=="hpca11_h_size_avg" 
replace c = 10 if yvar=="work_pooled_ag_p_11"
replace c = 11 if yvar=="work_pooled_ag_m_11" 
replace c = 12 if yvar=="work_pooled_ag_f_11"
replace c = 13 if yvar=="work_pooled_ot_p_11"
replace c = 14 if yvar=="work_pooled_ot_m_11" 
replace c = 15 if yvar=="work_pooled_ot_f_11"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==9
set obs 15
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 7/15 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_ec_badshapefiles.dta", clear
keep if rf_step==1
assert ifs=="in_rf_sample==1 & pop_mismatch20==0"
assert fe=="STFErf*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 16 if yvar=="ec_firms2013" 
replace c = 17 if yvar=="ec_employees2013"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==2
set obs 17
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 16/17 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

		
	
***	

use "$results/RDROBUST_outcomes_rf_schools_badshapefiles.dta", clear
keep if rf_step==1
assert ifs=="in_rf_sample==1 & pop_mismatch20==0"
assert fe=="STFErf*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 18 if yvar=="g15_enroll_all2014" 
replace c = 19 if yvar=="g68_enroll_all2014"
replace c = 20 if yvar=="tot_pass60_prev452014" 
replace c = 21 if yvar=="tot_pass60_prev782014"
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==4
set obs 21
gen blank = c==.
gsort -blank c 
assert blank | c==_n

forvalues c = 18/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}
	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = min(r(min),`bw_min')
local bw_max = max(r(max),`bw_max')

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
		
		
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_outcomes_bad_shapefiles.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- reduced-form outcomes, including unreliable/missing shapefiles}" _n
file write tablewrite "\label{tab:rd_outcomes_bad_shapefiles}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Consumption and income (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Expenditure per capita (Rs/month)~~~~ & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Expenditure per capita (logged)  & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share HH with poverty indicator  & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Share HH rely on cultivation income & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "~~Share HH earning \$>\$ Rs 5k/mth & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Share HH with salaried job       & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Population  & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Share population age 0--6 & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "~~Average household size    & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2011)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Ag workers, total      & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~Ag workers, male       & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~Ag workers, female     & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "~~Non-ag workers, total  & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~Non-ag workers, male   & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Non-ag workers, female & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Firm outcomes (2013)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Number of firms          & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "~~Number of firm employees & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & `ymean17' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{School outcomes (2014--15 school year)}~~} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~\# students enrolled, grades 1--5  & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & `ymean18' \\" _n
file write tablewrite "~~\# students enrolled, grades 6--8  & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & `ymean19' \\" _n
file write tablewrite "~~\# students passed, grades 4--5    & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & `ymean20' \\" _n
file write tablewrite "~~\# students passed, grades 7--8    & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & `ymean21' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- RD estimates in this table are identical to those in Table \ref*{tab:rd_outcomes}, " _n
file write tablewrite "except that here, we (i) expand our estimation sample to include 10 states with unreliable (or missing) " _n
file write tablewrite "village shapefiles, and (ii) do not control for pre-RGGVY village-level brightnness." _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table B6: RD covariate smoothness, 2001 Census variables
{

use "$results/RDROBUST_smoothness_census.dta", clear
keep if rf_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFEfs*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="pct_06_01" 
replace c = 2 if yvar=="lit_p_01"
replace c = 3 if yvar=="pct_scst_01" 
replace c = 4 if yvar=="work_p_01" 
replace c = 5 if yvar=="work_m_01" 
replace c = 6 if yvar=="work_f_01" 
replace c = 7 if yvar=="work_pooled_ag_p_01" 
replace c = 8 if yvar=="work_pooled_ot_p_01"
replace c = 9 if yvar=="vd_pwr_d_any_01"
replace c = 10 if yvar=="vd_pwr_d_dom_01"
replace c = 11 if yvar=="vd_pwr_d_agr_01"
replace c = 12 if yvar=="vd_pwr_d_all_01" 
replace c = 13 if yvar=="vd_wat_d_any_01"
replace c = 14 if yvar=="vd_wat_d_tubewell_01"
replace c = 15 if yvar=="pct_irr_01"
replace c = 16 if yvar=="vd_geo_k_town_01"
replace c = 17 if yvar=="index_vd_edu01"
replace c = 18 if yvar=="index_vd_hea01"
replace c = 19 if yvar=="index_vd_fin01"
replace c = 20 if yvar=="index_vd_com01"
replace c = 21 if yvar=="index_vd_tra01"
 
keep if c!=.
unique c
assert r(unique)==r(N) & r(unique)==21
sort c

forvalues c = 1/21 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local lci`c' = string(lci_robust[`c'], "%9.3f")
	local uci`c' = string(uci_robust[`c'], "%9.3f")
	
	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	

assert bw_lo==bw_hi
sum bw_lo
local bw_min = r(min)
local bw_max = r(max)

local bw_min = string(floor(`bw_min'),"%9.0f")
local bw_max = string(floor(`bw_max'),"%9.0f")	
		
		
***	

   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_rd_cov_smoothness.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD -- smoothness in pre-determined covariates}" _n
file write tablewrite "\label{tab:rd_cov_smoothness}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& RD estimate & Std error & 95\% CI & Mean \$ Y_v\$ \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.85cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\multicolumn{2}{l}{\textbf{A.} \underline{Electricity access in village (2001)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~1/0 anywhere in village   & $`beta9'$`stars9' & $(`se9')$ & $[`lci9',`uci9']$ & `ymean9' \\" _n
file write tablewrite "~~1/0 domestic sector       & $`beta10'$`stars10' & $(`se10')$ & $[`lci10',`uci10']$ & `ymean10' \\" _n
file write tablewrite "~~1/0 agricultural sector   & $`beta11'$`stars11' & $(`se11')$ & $[`lci11',`uci11']$ & `ymean11' \\" _n
file write tablewrite "~~1/0 all sectors           & $`beta12'$`stars12' & $(`se12')$ & $[`lci12',`uci12']$ & `ymean12' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{B.} \underline{Village demographics (2001)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Share population age 0--6              & $`beta1'$`stars1' & $(`se1')$ & $[`lci1',`uci1']$ & `ymean1' \\" _n
file write tablewrite "~~Literacy rate                          & $`beta2'$`stars2' & $(`se2')$ & $[`lci2',`uci2']$ & `ymean2' \\" _n
file write tablewrite "~~Share Scheduled Caste/Scheduled Tribe  & $`beta3'$`stars3' & $(`se3')$ & $[`lci3',`uci3']$ & `ymean3' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{C.} \underline{Workers as share of population (2001)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~All workers             & $`beta4'$`stars4' & $(`se4')$ & $[`lci4',`uci4']$ & `ymean4' \\" _n
file write tablewrite "~~Male workers            & $`beta5'$`stars5' & $(`se5')$ & $[`lci5',`uci5']$ & `ymean5' \\" _n
file write tablewrite "~~Female workers          & $`beta6'$`stars6' & $(`se6')$ & $[`lci6',`uci6']$ & `ymean6' \\" _n
file write tablewrite "~~Ag workers, total       & $`beta7'$`stars7' & $(`se7')$ & $[`lci7',`uci7']$ & `ymean7' \\" _n
file write tablewrite "~~Non-ag workers, total   & $`beta8'$`stars8' & $(`se8')$ & $[`lci8',`uci8']$ & `ymean8' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{D.} \underline{Village characteristics (2001)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~1/0 village has drinking water   & $`beta13'$`stars13' & $(`se13')$ & $[`lci13',`uci13']$ & `ymean13' \\" _n
file write tablewrite "~~1/0 village has tubewell         & $`beta14'$`stars14' & $(`se14')$ & $[`lci14',`uci14']$ & `ymean14' \\" _n
file write tablewrite "~~Share of village land irrigated  & $`beta15'$`stars15' & $(`se15')$ & $[`lci15',`uci15']$ & `ymean15' \\" _n
file write tablewrite "~~Distance to nearest town (km)    & $`beta16'$`stars16' & $(`se16')$ & $[`lci16',`uci16']$ & `ymean16' \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "\multicolumn{2}{l}{\textbf{E.} \underline{Indexes of village amenities (2001)}} \\ " _n
file write tablewrite "[0.15em] " _n
file write tablewrite "~~Schooling access (7 variables)          & $`beta17'$`stars17' & $(`se17')$ & $[`lci17',`uci17']$ & $`ymean17'$ \\" _n
file write tablewrite "~~Health services access (8 variables)    & $`beta18'$`stars18' & $(`se18')$ & $[`lci18',`uci18']$ & $`ymean18'$ \\" _n
file write tablewrite "~~Financial services access (4 variables) & $`beta19'$`stars19' & $(`se19')$ & $[`lci19',`uci19']$ & $`ymean19'$ \\" _n
file write tablewrite "~~Communication access (4 variables)      & $`beta20'$`stars20' & $(`se20')$ & $[`lci20',`uci20']$ & $`ymean20'$ \\" _n
file write tablewrite "~~Transportation access (4 variables)     & $`beta21'$`stars21' & $(`se21')$ & $[`lci21',`uci21']$ & $`ymean21'$ \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This table is analogous to Tables \ref*{tab:rd_outcomes}  " _n
file write tablewrite "and \ref{tab:rd_outcomes_bonus}, using 2001 Census covariates as dependent variables. " _n
file write tablewrite "RD robust regressions control only for state fixed effects, but are otherwise identical to our preferred specification. " _n
file write tablewrite "Of the four covariates with weak statistical significance, three are not robust to alternative kernels and fixed effects " _n
file write tablewrite "(share population age 0--6, all workers, and financial services access). " _n
file write tablewrite "Optimal bandwidths in the table range from `bw_min' to `bw_max' above/below 300 people. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Figure B7: RD covariate smoothness, 2001 Census variables
{
foreach f in pct_06_01 work_p_01 work_f_01 index_vd_fin01 vd_pwr_d_any_01 vd_pwr_d_agr_01 vd_pwr_d_dom_01 vd_pwr_d_all_01 {
	copy "${results}/RDROBUST plots rf outcomes preferred/`f'_PRE_fs_inreg_10.pdf" "${texfig}/`f'_PRE_fs_inreg_10.pdf" , replace
}

   // MAKE FIGURE
cap file close tablewrite
file open tablewrite using "$texfig/figure_rd_cov_smoothness.tex", write text replace
 
file write tablewrite "\begin{figure}[h!]\centering" _n
file write tablewrite "\caption{Village-level RDs in pre-determined covariates}" _n
file write tablewrite "\label{fig:rd_pre}" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/vd_pwr_d_any_01_PRE_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/vd_pwr_d_dom_01_PRE_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/vd_pwr_d_agr_01_PRE_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/vd_pwr_d_all_01_PRE_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/pct_06_01_PRE_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_p_01_PRE_fs_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/work_f_01_PRE_fs_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.43\textwidth]{${texfig_short}/index_vd_fin01_PRE_fs_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- These RD plots correspond to eight regressions in Table \ref*{tab:rd_cov_smoothness}: " _n
file write tablewrite "the four electricity access dummies in the 2001 Census, and the four pre-determined covariates with " _n
file write tablewrite "weakly statistical significant RD estimates. " _n
file write tablewrite "See table notes for details." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite



}

********************************************************************************
********************************************************************************
